﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace DrawTools.Attach
{
    public static class IconElement
    {
        public static readonly DependencyProperty ImageProperty = DependencyProperty.RegisterAttached("Image", typeof(object), typeof(IconElement));

        public static void SetImage(DependencyObject element, object value)
        {
            if (value is string s)
            {
                value = new BitmapImage(new Uri(value.ToString(), UriKind.Relative));
            }
            element.SetValue(ImageProperty, value);
        }

        public static ImageSource GetImage(DependencyObject element) => (ImageSource)element.GetValue(ImageProperty);

        public static readonly DependencyProperty ImageSelectedProperty = DependencyProperty.RegisterAttached("ImageSelected", typeof(object), typeof(IconElement));

        public static void SetImageSelected(DependencyObject element, object value)
        {
            if (value is string s)
            {
                value = new BitmapImage(new Uri(value.ToString(), UriKind.Relative));
            }
            element.SetValue(ImageSelectedProperty, value);
        }

        public static ImageSource GetImageSelected(DependencyObject element) => (ImageSource)element.GetValue(ImageSelectedProperty);
    }
}